package com.bestcem.xm.ticket.enums;

import cn.hutool.core.util.ObjectUtil;

/**
 * 文本中字段类型
 *
 * @author xuan.yang <xuan.yang@idiaoyan.com>
 * @version v2.3
 * @date 2021/9/2 11:04
 */
public enum TemplateFieldTypeEnum {

    /**
     * 单行
     */
    TEXT(1, "text"),
    /**
     * 多行
     */
    MULTI_LINE(2, "multiLine"),
    /**
     * 单选
     */
    SELECT(3, "select"),
    /**
     * 级联选择
     */
    CASCADE_SELECT(4, "cascadeSelect");

    private final Integer index;

    private final String name;

    public Integer getIndex() {
        return index;
    }

    public String getName() {
        return name;
    }

    TemplateFieldTypeEnum(Integer index, String name) {
        this.index = index;
        this.name = name;
    }

    /**
     * 根据 index 获取枚举实体
     * 找不到则返回 null
     *
     * @param index
     * @return
     */
    public static TemplateFieldTypeEnum getByIndex(Integer index) {
        for (TemplateFieldTypeEnum fieldTypeEnum : TemplateFieldTypeEnum.values()) {
            if (ObjectUtil.equal(fieldTypeEnum.index, index)) {
                return fieldTypeEnum;
            }
        }
        return null;
    }

    /**
     * 通过name获取枚举的code
     *
     * @param name
     * @return
     */
    public static TemplateFieldTypeEnum getByName(String name) {
        for (TemplateFieldTypeEnum fieldTypeEnum : TemplateFieldTypeEnum.values()) {
            if (ObjectUtil.equal(fieldTypeEnum.name, name)) {
                return fieldTypeEnum;
            }
        }
        return null;
    }

}
